package com.kitty.game.task.service.taskHandler;

import com.kitty.game.role.model.Role;
import com.kitty.game.config.TaskSet;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.enter.RespNotifyMisc;
import com.kitty.game.task.TaskDataPool;
import com.kitty.game.task.model.product.TaskType;
import com.kitty.game.task.service.NewTaskService;
import com.kitty.game.utils.AsktaoUtil;
import com.kitty.game.utils.Const;
import com.kitty.mina.message.MessagePusher;
import org.springframework.stereotype.Service;

@Service
public class MainTaskHandler extends TaskHandler {
    /**接取第一个主线任务，创建角色时需要接取*/
    public void acceptFirstMainTask(Role role) {
        NewTaskService taskService = SpringUtils.getBean(NewTaskService.class);
        TaskSet firstMainTask = taskService.getTaskSet(TaskDataPool.FIRST_MAIN_TASKID, role);
        acceptTask(role, firstMainTask);
    }

    @Override
    public boolean resetTask(Role role, TaskSet taskSet) {
        /**主线任务不能重置*/
        return false;
    }

    @Override
    public TaskType getTaskType() {
        return TaskType.MAIN_LINE;
    }

    @Override
    public void giveReward(Role role, TaskSet taskSet) {
        super.giveReward(role, taskSet);

        /**指定任务id，设置为100天道行*/
        if (taskSet.getId() == TaskDataPool.MAIN_SCHOOL_TITLE_TASKID) {
            long taoPoint = 100 * Const.ONE_DAY_POINT;
            long oldTaoPoint = role.getTaoPoint();
            if (oldTaoPoint < taoPoint) {
                role.setTaoPoint(taoPoint);
                role.save();

                SpringUtils.getRoleService().sendExtraAttribute(role);
                MessagePusher.pushMessage(role, new RespNotifyMisc("你获得了" + AsktaoUtil.getFormatTao((int) (taoPoint-oldTaoPoint)) + "道行。"));
            }
        }
    }
}
